import 'package:flutter/material.dart';
import 'package:website.core/core/presentation/theme/theme.dart';

part 'styles.dart';

part 'text_theme.dart';

class WebPurchaseItemPageTheme extends InheritedTheme {
  WebPurchaseItemPageTheme({
    required Brightness brightness,
    required Color primaryContrastingColor,
    required Widget child,
    Key? key,
  })  : _brightness = brightness,
        _primaryContrastingColor = primaryContrastingColor,
        _data = _buildThemeData(
          brightness: brightness,
          primaryContrastingColor: primaryContrastingColor,
        ),
        super(
          key: key,
          child: child,
        );

  final Brightness _brightness;
  final Color _primaryContrastingColor;
  final WebPurchaseItemPageThemeData _data;

  static WebPurchaseItemPageThemeData _buildThemeData({
    required Brightness brightness,
    required Color primaryContrastingColor,
  }) {
    return WebPurchaseItemPageThemeData.dark(
      primaryContrastingColor: primaryContrastingColor,
    );
  }

  static WebPurchaseItemPageThemeData of(BuildContext context) {
    final inheritedTheme = context.dependOnInheritedWidgetOfExactType<WebPurchaseItemPageTheme>()!;
    return inheritedTheme._data;
  }

  @override
  Widget wrap(BuildContext context, Widget child) {
    final ancestorTheme = context.findAncestorWidgetOfExactType<WebPurchaseItemPageTheme>();

    if (identical(this, ancestorTheme)) {
      return child;
    }

    return WebPurchaseItemPageTheme(
      brightness: _brightness,
      primaryContrastingColor: _primaryContrastingColor,
      child: child,
    );
  }

  @override
  bool updateShouldNotify(WebPurchaseItemPageTheme oldWidget) {
    return _brightness != oldWidget._brightness ||
        _primaryContrastingColor != oldWidget._primaryContrastingColor;
  }
}

class WebPurchaseItemPageThemeData {
  const WebPurchaseItemPageThemeData._internal({
    required this.imageBackgroundColor,
    required this.backgroundColor,
    required this.imageFloorColor,
    required this.purchaseItemTileColor,
    required this.pageClosingIconColor,
    required this.purchaseItemTileShadows,
    required this.textTheme,
  });

  factory WebPurchaseItemPageThemeData.dark({
    required Color primaryContrastingColor,
  }) {
    return WebPurchaseItemPageThemeData._internal(
      imageBackgroundColor: WebPurchaseItemPageStyles.imageBackgroundColorDark,
      backgroundColor: CoreStyles.darkGrey4,
      imageFloorColor: WebPurchaseItemPageStyles.imageFloorColorDark,
      purchaseItemTileColor: WebPurchaseItemPageStyles.inAppPurchaseTileColorDark,
      pageClosingIconColor: CoreStyles.grey2,
      purchaseItemTileShadows: const [],
      textTheme: WebPurchaseItemPageTextTheme.dark(
        primaryContrastingColor: primaryContrastingColor,
      ),
    );
  }

  final Color imageBackgroundColor;
  final Color backgroundColor;
  final Color imageFloorColor;
  final Color purchaseItemTileColor;
  final Color pageClosingIconColor;
  final List<BoxShadow> purchaseItemTileShadows;
  final WebPurchaseItemPageTextTheme textTheme;
}
